'use strict';

module.exports = function countSameElements(collection) {
  let arr = [];
  let obj = {}; //创建一个空对象 
  for(let item of collection){
    // for of 遍历对象元素
    if(!obj[item]){
      obj[item] = {} ;
      obj[item].key = item ;
      obj[item].count = 1;
    }else{  
      obj[item].count++;
    }
  }
for(let item in obj){
  // for in 遍历对象属性
  arr.push(obj[item]);
}
return arr;
}